package v3.chapter2.synLockIn_2;

public class Run {

	public static void main(String[] args) {
		MyThread t=new MyThread();
		t.start();

	}

}

class MyThread extends Thread{
	@Override
	public void run() {
		Sub sub=new Sub();
		sub.operateIMainMethod();
	}
 
}

class Sub extends Main {
	@Override
	public synchronized void operateIMainMethod() {
		try {
			while (i > 0) {
				i--;
				System.out.println("sub print i=" + i);
				Thread.sleep(100);
				super.operateIMainMethod();
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}

class Main {
	public int i = 10;

	synchronized public void operateIMainMethod() {
		try {
			i--;
			System.out.println("main print j=" + i);
			Thread.sleep(100);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}